<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>关键问题1</title>
</head>
<body>
  <!-- 
			1.如何改变一个Promise实例的状态?
							(1)resolve(value): 如果当前是pendding就会变为resolved
							(2)reject(reason): 如果当前是pendding就会变为rejected
							(3)执行器函数(excutor)抛出异常: 如果当前是pendding就会变为rejected
			
			2.一个promise指定多个成功/失败回调函数, 都会调用吗? —————— 会
	-->

	<script type="text/javascript" >

		//如何改变一个Promise实例的状态
		/* const p = new Promise((resolve,reject)=>{
			// console.log(x) //js引擎抛出异常
			// throw 900 //程序员亲自抛异常

			// setTimeout(()=>{
			// 	reject('hello')
			// },1000)
		})

		p.then(
			value => {console.log('成功了',value)},
			reason => {console.log('失败了',reason)}
		) */

		//给一个Promise实例指定多组成功、失败的回调
		/* const p = new Promise((resolve,reject)=>{
			setTimeout(()=>{
				resolve('hello')
			},1000)
		})
		p.then(
			value => {console.log('成功了1',value)},
			reason => {console.log('失败了1',reason)}
		)
		p.then(
			value => {console.log('成功了2',value)},
			reason => {console.log('失败了2',reason)}
		) */

		//一个小问题的说明
		const p = new Promise((resolve,reject)=>{
			setTimeout(()=>{
				reject('hello')
			},1000)
		})

		p.then(
			value => {console.log('成功了',value)}
		)
		p.catch(
			reason => {console.log('失败了',reason)}
		)

	</script>
</body>
</html>